/*
 * My97 DatePicker 4.8
 * License: http://www.my97.net/license.asp
 */
var $_$dp, WdatePicker;

var $_$dp_calendarPath = fb.data.base + "resource/fb-form/datepicker/calendar.min.js";
var $_$dp_langPath = fb.data.base + "resource/fb-form/datepicker/lang/{name}.min.js";
var $_$dp_skinPath = fb.data.base + "resource/fb-form/datepicker/skin/{name}/datepicker.css";

var dp =  (function () {
	var l = {
		$_$langList: [
			{name: "en", charset: "UTF-8"},
			{name: "zh-cn", charset: "gb2312"},
			{name: "zh-tw", charset: "GBK"}
		],
		$_$skinList: [
			{name: "default", charset: "gb2312"},
			{name: "whyGreen", charset: "gb2312"},
			{name: "blue", charset: "gb2312"},
			{name: "green", charset: "gb2312"},
			{name: "simple", charset: "gb2312"},
			{name: "ext", charset: "gb2312"},
			{name: "blueFresh", charset: "gb2312"},
			{name: "twoer", charset: "gb2312"},
			{name: "YcloudRed", charset: "gb2312"}],
		$_$wdate: true,
		$_$crossFrame: false,
		$_$preLoad: false,
		$_$dpPath: "",
		doubleCalendar: false,
		enableKeyboard: true,
		enableInputMask: true,
		autoUpdateOnChanged: null,
		weekMethod: "MSExcel",
		position: {},
		lang: "zh-cn",
		skin: "twoer",
		dateFmt: "yyyy-MM-dd",
		realDateFmt: "yyyy-MM-dd",
		realTimeFmt: "HH:mm:ss",
		realFullFmt: "%Date %Time",
		minDate: "0001-01-01 00:00:00",
		maxDate: "9999-12-31 23:59:59",
		minTime: "00:00:00",
		maxTime: "23:59:59",
		startDate: "",
		alwaysUseStartDate: false,
		yearOffset: 1911,
		firstDayOfWeek: 0,
		isShowWeek: false,
		highLineWeekDay: true,
		isShowClear: true,
		isShowToday: true,
		isShowOK: true,
		isShowOthers: true,
		readOnly: false,
		errDealMode: 0,
		autoPickDate: null,
		qsEnabled: true,
		autoShowQS: false,
		hmsMenuCfg: {H: [1, 6], m: [5, 6], s: [15, 4]},

		opposite: false,
		specialDates: null,
		specialDays: null,
		disabledDates: null,
		disabledDays: null,
		onpicking: null,
		onpicked: null,
		onclearing: null,
		oncleared: null,
		ychanging: null,
		ychanged: null,
		Mchanging: null,
		Mchanged: null,
		dchanging: null,
		dchanged: null,
		Hchanging: null,
		Hchanged: null,
		mchanging: null,
		mchanged: null,
		schanging: null,
		schanged: null,
		eCont: null,
		vel: null,
		elProp: "",
		errMsg: "",
		quickSel: [],
		has: {},
		getRealLang: function () {
			var d = l.$_$langList;
			for (var e = 0; e < d.length; e++) {
				if (d[e].name == this.lang) {
					return d[e]
				}
			}
			return d[0]
		}
	};
	WdatePicker = g;
	var n = window, i = {innerHTML: ""}, z = "document", B = "documentElement", H = "getElementsByTagName", E, u, h, f,
		D;
	var v = navigator.appName;
	if (v == "Microsoft Internet Explorer") {
		h = true
	} else {
		if (v == "Opera") {
			D = true
		} else {
			f = true
		}
	}
	u = l.$_$dpPath || q();
	if (l.$_$wdate) {
		m(u + "skin/WdatePicker.css")
	}
	E = n;
	if (l.$_$crossFrame) {
		try {
			while (E.parent != E && E.parent[z][H]("frameset").length == 0) {
				E = E.parent
			}
		} catch (y) {
		}
	}
	if (!E.$_$dp) {
		E.$_$dp = {ff: f, ie: h, opera: D, status: 0, defMinDate: l.minDate, defMaxDate: l.maxDate}
	}
	b();
	if (l.$_$preLoad && $_$dp.status == 0) {
		k(n, "onload", function () {
			g(null, true)
		})
	}
	if (!n[z].docMD) {
		k(n[z], "onmousedown", s, true);
		n[z].docMD = true
	}
	if (!E[z].docMD) {
		k(E[z], "onmousedown", s, true);
		E[z].docMD = true
	}
	k(n, "onunload", function () {
		if ($_$dp.dd) {
			r($_$dp.dd, "none")
		}
	});

	function b() {
		try {
			E[z], E.$_$dp = E.$_$dp || {}
		} catch (I) {
			E = n;
			$_$dp = $_$dp || {}
		}
		var w = {
			win: n, $_$: function (e) {
				return (typeof e == "string") ? n[z].getElementById(e) : e
			}, $_$D: function (J, e) {
				return this.$_$DV(this.$_$(J).value, e)
			}, $_$DV: function (J, e) {
				if (J != "") {
					this.dt = $_$dp.cal.splitDate(J, $_$dp.cal.dateFmt);
					if (e) {
						for (var L in e) {
							if (this.dt[L] === undefined) {
								this.errMsg = "invalid property:" + L
							} else {
								this.dt[L] += e[L];
								if (L == "M") {
									var M = e.M > 0 ? 1 : 0;
									var K = new Date(this.dt.y, this.dt.M, 0).getDate();
									this.dt.d = Math.min(K + M, this.dt.d)
								}
							}
						}
					}
					if (this.dt.refresh()) {
						return this.dt
					}
				}
				return ""
			}, show: function () {
				var K = E[z].getElementsByTagName("div"), J = 100000;
				for (var e = 0; e < K.length; e++) {
					var L = parseInt(K[e].style.zIndex);
					if (L > J) {
						J = L
					}
				}
				this.dd.style.zIndex = J + 2;
				r(this.dd, "block");
				r(this.dd.firstChild, "")
			}, unbind: function (e) {
				e = this.$_$(e);
				if (e.initcfg) {
					t(e, "onclick", function () {
						g(e.initcfg)
					});
					t(e, "onfocus", function () {
						g(e.initcfg)
					})
				}
			}, hide: function () {
				r(this.dd, "none")
			}, attachEvent: k
		};
		for (var d in w) {
			E.$_$dp[d] = w[d]
		}
		$_$dp = E.$_$dp
	}

	function k(I, J, w, d) {
		if (I.addEventListener) {
			var e = J.replace(/on/, "");
			w._ieEmuEventHandler = function (K) {
				return w(K)
			};
			I.addEventListener(e, w._ieEmuEventHandler, d)
		} else {
			I.attachEvent(J, w)
		}
	}

	function t(w, I, e) {
		if (w.removeEventListener) {
			var d = I.replace(/on/, "");
			e._ieEmuEventHandler = function (J) {
				return e(J)
			};
			w.removeEventListener(d, e._ieEmuEventHandler, false)
		} else {
			w.detachEvent(I, e)
		}
	}

	function C(w, e, d) {
		if (typeof w != typeof e) {
			return false
		}
		if (typeof w == "object") {
			if (!d) {
				for (var I in w) {
					if (typeof e[I] == "undefined") {
						return false
					}
					if (!C(w[I], e[I], true)) {
						return false
					}
				}
			}
			return true
		} else {
			if (typeof w == "function" && typeof e == "function") {
				return w.toString() == e.toString()
			} else {
				return w == e
			}
		}
	}

	function q() {
		var I, w, d = n[z][H]("script");
		for (var e = 0; e < d.length; e++) {
			I = d[e].getAttribute("src") || "";
			I = I.substr(0, I.toLowerCase().indexOf("wdatepicker.js"));
			var w = I.lastIndexOf("/");
			if (w > 0) {
				I = I.substring(0, w + 1)
			}
			if (I) {
				break
			}
		}
		return I
	}

	function m(w, I, J) {
		var d = n[z][H]("HEAD").item(0), e = n[z].createElement("link");
		if (d) {
			e.href = w;
			e.rel = "stylesheet";
			e.type = "text/css";
			if (I) {
				e.title = I
			}
			if (J) {
				e.charset = J
			}
			d.appendChild(e)
		}
	}

	function p(I) {
		I = I || E;
		var L = 0, d = 0;
		while (I != E) {
			var N = I.parent[z][H]("iframe");
			for (var J = 0; J < N.length; J++) {
				try {
					if (N[J].contentWindow == I) {
						var K = o(N[J]);
						L += K.left;
						d += K.top;
						break
					}
				} catch (M) {
				}
			}
			I = I.parent
		}
		return {leftM: L, topM: d}
	}

	function o(I, w) {
		if (I.getBoundingClientRect) {
			return I.getBoundingClientRect()
		} else {
			var J = {ROOT_TAG: /^body|html$_$/i, OP_SCROLL: /^(?:inline|table-row)$_$/i};
			var e = false, M = null, P = I.offsetTop, K = I.offsetLeft, d = I.offsetWidth, O = I.offsetHeight;
			var L = I.offsetParent;
			if (L != I) {
				while (L) {
					K += L.offsetLeft;
					P += L.offsetTop;
					if (c(L, "position").toLowerCase() == "fixed") {
						e = true
					} else {
						if (L.tagName.toLowerCase() == "body") {
							M = L.ownerDocument.defaultView
						}
					}
					L = L.offsetParent
				}
			}
			L = I.parentNode;
			while (L.tagName && !J.ROOT_TAG.test(L.tagName)) {
				if (L.scrollTop || L.scrollLeft) {
					if (!J.OP_SCROLL.test(r(L))) {
						if (!D || L.style.overflow !== "visible") {
							K -= L.scrollLeft;
							P -= L.scrollTop
						}
					}
				}
				L = L.parentNode
			}
			if (!e) {
				var N = F(M);
				K -= N.left;
				P -= N.top
			}
			d += K;
			O += P;
			return {left: K, top: P, right: d, bottom: O}
		}
	}

	function x(e) {
		e = e || E;
		var J = e[z],
			I = (e.innerWidth) ? e.innerWidth : (J[B] && J[B].clientWidth) ? J[B].clientWidth : J.body.offsetWidth,
			d = (e.innerHeight) ? e.innerHeight : (J[B] && J[B].clientHeight) ? J[B].clientHeight : J.body.offsetHeight;
		return {width: I, height: d}
	}

	function F(e) {
		e = e || E;
		var J = e[z], d = J[B], I = J.body;
		J = (d && d.scrollTop != null && (d.scrollTop > I.scrollTop || d.scrollLeft > I.scrollLeft)) ? d : I;
		return {top: J.scrollTop, left: J.scrollLeft}
	}

	function s(d) {
		try {
			var w = d ? (d.srcElement || d.target) : null;
			if ($_$dp.cal && !$_$dp.eCont && $_$dp.dd && w != $_$dp.el && $_$dp.dd.style.display == "block") {
				$_$dp.cal.close()
			}
		} catch (d) {
		}
	}

	function A() {
		$_$dp.status = 2
	}

	var G, j;

	function g(M, d) {
		if (!$_$dp) {
			return
		}
		b();
		var J = {};
		for (var L in M) {
			J[L] = M[L]
		}
		for (var L in l) {
			if (L.substring(0, 1) != "$_$" && J[L] === undefined) {
				J[L] = l[L]
			}
		}
		if (d) {
			if (!w()) {
				j = j || setInterval(function () {
					if (E[z].readyState == "complete") {
						clearInterval(j)
					}
					g(null, true)
				}, 50);
				return
			}
			if ($_$dp.status == 0) {
				$_$dp.status = 1;
				J.el = i;
				a(J, true)
			} else {
				return
			}
		} else {
			if (J.eCont) {
				J.eCont = $_$dp.$_$(J.eCont);
				J.el = i;
				J.autoPickDate = true;
				J.qsEnabled = false;
				a(J)
			} else {
				if (l.$_$preLoad && $_$dp.status != 2) {
					return
				}
				var I = N();
				if (n.event === I || I) {
					J.srcEl = I.srcElement || I.target;
					I.cancelBubble = true
				}
				J.el = J.el = $_$dp.$_$(J.el || J.srcEl);
				if (J.el == null) {
					alert("WdatePicker:el is null!\nexample:onclick=\"WdatePicker({el:this})\"");
					return;
				}
				try {
					if (!J.el || J.el.My97Mark === true || J.el.disabled || ($_$dp.dd && r($_$dp.dd) != "none" && $_$dp.dd.style.left != "-970px")) {
						if (J.el.My97Mark) {
							J.el.My97Mark = false
						}
						return
					}
				} catch (K) {
				}
				if (I && J.el.nodeType == 1 && !C(J.el.initcfg, M)) {
					$_$dp.unbind(J.el);
					k(J.el, I.type == "focus" ? "onclick" : "onfocus", function () {
						g(M)
					});
					J.el.initcfg = M
				}
				a(J)
			}
		}

		function w() {
			if (h && E != n && E[z].readyState != "complete") {
				return false
			}
			return true
		}

		function N() {
			if (f) {
				try {
					func = N.caller;
					while (func != null) {
						var O = func.arguments[0];
						if (O && (O + "").indexOf("Event") >= 0) {
							return O
						}
						func = func.caller
					}
				} catch (P) {
				}
				return null
			}
			return event
		}
	}

	function c(e, d) {
		return e.currentStyle ? e.currentStyle[d] : document.defaultView.getComputedStyle(e, false)[d]
	}

	function r(e, d) {
		if (e) {
			if (d != null) {
				e.style.display = d
			} else {
				return c(e, "display")
			}
		}
	}

	function a(e, d) {
		var K = e.el ? e.el.nodeName : "INPUT";
		if (d || e.eCont || new RegExp(/input|textarea|div|span|p|a/ig).test(K)) {
			e.elProp = K == "INPUT" ? "value" : "innerHTML"
		} else {
			return
		}
		if (e.lang == "auto") {
			e.lang = h ? navigator.browserLanguage.toLowerCase() : navigator.language.toLowerCase()
		}
		if (!e.eCont) {
			for (var J in e) {
				$_$dp[J] = e[J]
			}
		}
		if (!$_$dp.dd || e.eCont || ($_$dp.dd && (e.getRealLang().name != $_$dp.dd.lang || e.skin != $_$dp.dd.skin))) {
			if (e.eCont) {
				w(e.eCont, e)
			} else {
				$_$dp.dd = E[z].createElement("DIV");
				$_$dp.dd.style.cssText = "position:absolute";
				E[z].body.appendChild($_$dp.dd);
				w($_$dp.dd, e);
				if (d) {
					$_$dp.dd.style.left = $_$dp.dd.style.top = "-970px"
				} else {
					$_$dp.show();
					I($_$dp)
				}
			}
		} else {
			if ($_$dp.cal) {
				$_$dp.show();
				$_$dp.cal.init();
				if (!$_$dp.eCont) {
					I($_$dp)
				}
			}
		}

		function w(V, P) {
			var O = E[z].domain, S = false,
				M = '<iframe hideFocus=true width=9 height=7 frameborder=0 border=0 scrolling=no src="about:blank"></iframe>';
			V.innerHTML = M;
			var L = l.$_$langList, U = l.$_$skinList, T;
			try {
				T = V.lastChild.contentWindow[z]
			} catch (Q) {
				S = true;
				V.removeChild(V.lastChild);
				var N = E[z].createElement("iframe");
				N.hideFocus = true;
				N.frameBorder = 0;
				N.scrolling = "no";
				N.src = "javascript:(function(){var d=document;d.open();d.domain='" + O + "';})()";
				V.appendChild(N);
				setTimeout(function () {
					T = V.lastChild.contentWindow[z];
					R()
				}, 97);
				return
			}
			R();

			function R() {
				var Y = P.getRealLang();
				V.lang = Y.name;
				V.skin = P.skin;
				var X = ["<head><script>", "", "var doc=document, $_$d, $_$dp, $_$cfg=doc.cfg, $_$pdp = parent.$_$dp, $_$dt, $_$tdt, $_$sdt, $_$lastInput, $_$IE=$_$pdp.ie, $_$FF = $_$pdp.ff,$_$OPERA=$_$pdp.opera, $_$ny, $_$cMark = false;", "if($_$cfg.eCont){$_$dp = {};for(var p in $_$pdp)$_$dp[p]=$_$pdp[p];}else{$_$dp=$_$pdp;};for(var p in $_$cfg){$_$dp[p]=$_$cfg[p];}", "doc.oncontextmenu=function(){try{$_$c._fillQS(!$_$dp.has.d,1);showB($_$d.qsDivSel);}catch(e){};return false;};", "<\/script><script src=", u, "lang/", Y.name, ".js charset=", Y.charset, "><\/script>"];
				if (S) {
					X[1] = 'document.domain="' + O + '";'
				}
				for (var W = 0; W < U.length; W++) {
					if (U[W].name == P.skin) {
						X.push('<link rel="stylesheet" type="text/css" href="' + u + "skin/" + U[W].name + '/datepicker.css" charset="' + U[W].charset + '"/>')
					}
				}
				X.push('<script src="' + u + 'calendar.js"><\/script>');
				X.push('</head><body leftmargin="0" topmargin="0" tabindex=0></body></html>');
				X.push('<script>var t;t=t||setInterval(function(){if((typeof(doc.ready)=="boolean"&&doc.ready)||doc.readyState=="complete"){new My97DP();$_$cfg.onload();$_$c.autoSize();$_$cfg.setPos($_$dp);clearInterval(t);}},20);<\/script>');
				P.setPos = I;
				P.onload = A;
				T.write("<html>");
				T.cfg = P;
				T.write(X.join(""));
				T.close()
			}
		}

		function I(O) {
			var M = O.position.left, V = O.position.top, L = O.el;
			if (L == i) {
				return
			}
			if (L != O.srcEl && (r(L) == "none" || L.type == "hidden")) {
				L = O.srcEl
			}
			var T = o(L), P = p(n), U = x(E), Q = F(E), N = $_$dp.dd.offsetHeight, S = $_$dp.dd.offsetWidth;
			if (isNaN(V)) {
				V = 0
			}
			if ((P.topM + T.bottom + N > U.height) && (P.topM + T.top - N > 0)) {
				V += Q.top + P.topM + T.top - N - 2
			} else {
				V += Q.top + P.topM + T.bottom;
				var R = V - Q.top + N - U.height;
				if (R > 0) {
					V -= R
				}
			}
			if (isNaN(M)) {
				M = 0
			}
			M += Q.left + Math.min(P.leftM + T.left, U.width - S - 5) - (h ? 2 : 0);
			O.dd.style.top = V + "px";
			O.dd.style.left = M + "px"
		}
	}


	window.$_$dp = window.$_$dp = $_$dp;

	$_$dp.$_$D = $_$dp.$_$D;

	window.WdatePicker = WdatePicker;

	return {
		$_$dp: $_$dp,
		WdatePicker: WdatePicker
	};

})();



// 以下配置请勿轻易改动

window.$_$dp = window.$_$dp = dp.$_$dp;
window.WdatePicker = dp.WdatePicker;

if (typeof define == "undefined") {

} else {
	define(function (require, exports, module) {
		/**
		 * datepicker
		 * jQuery插件包装
		 * @param options
		 * @returns {*}
		 */
		$_$.fn.wdatepicker = function (options) {
			options = $_$.extend({}, {
				on: "focus click"
			}, options);
			return this.each(function () {
				$_$(this).on(options.on, function () {
					window.WdatePicker.apply(this, [$_$.extend({}, options || {})]);
				});
			});
		};

		module.exports = window.WdatePicker;
	});
}
